package com.ubs.training.server.service;

import com.ubs.training.prod.server.service.LoggingService;
import com.ubs.training.server.dao.ProductDao;
import com.ubs.training.server.dao.model.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: xubuntu
 * Date: 8/22/12
 * Time: 10:44 AM
 * To change this template use File | Settings | File Templates.
 */
@Service
public class ProductService {

    @Resource(name = "productDao")
    ProductDao dao;

    @Autowired
    LoggingService svc;
    public static final String USER_REQUESTS_ALL_PRODUCTS = "User requests all products";
    public static final String USER_ADDED_PRODUCT = "User added new product";
    public static final String USER_UPDATED_PRODUCT = "User updated product";
    public static final String USER_REMOVED_PRODUCT = "User removed product";
    public static final String USER_REQUESTS_PRODUCT_BY_ID = "User requests product by id";

    public ProductDao getDao() {
        return dao;
    }

    public void setDao(ProductDao dao) {
        this.dao = dao;
    }

    public LoggingService getSvc() {
        return svc;
    }

    public void setSvc(LoggingService svc) {
        this.svc = svc;
    }

    public List<Product> getByClientId(int id) {

        return dao.getByClientId(id);
    }

    public void saveProduct(Product product){
        if (product.getId_product()!=0){
            dao.update(product);

        } else {
            dao.add(product);

        }
    }

    public void deleteProduct(Product product){
        dao.remove(product);

    }

    public Product getProductById(int id){

        return dao.getById(id);
    }
}
